﻿// See https://aka.ms/new-console-template for more information
using AutoMapper;
using AutoMapperTest.Models;

Console.WriteLine("Hello, World!");
var configuration = new MapperConfiguration(cfg =>
{
    cfg.CreateMap<User, UserDto>().ForMember(des => des.Status, opt => opt.MapFrom(x => x.Status == 0 ? "正常" : "不可用")).ReverseMap();
});

#if DEBUG
configuration.AssertConfigurationIsValid();
#endif
// use DI (http://docs.automapper.org/en/latest/Dependency-injection.html) or create the mapper yourself
var mapper = configuration.CreateMapper();

User user = new User
{
    Id = 1,
    Name = "km",
    Email = "31231@qq.com",
    Password = "666",
    CreateTime = DateTime.Now,
    Status = 0
};
var userDto = mapper.Map<UserDto>(user);

//UserDto dto = new UserDto()
//{
//    Id = 1,
//    Name = "km",
//    Email = "31231@qq.com",
//    Password = "666",
//    Status = "不可用"
//};
//var user = mapper.Map<User>(dto);

Console.ReadKey();